<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>偏好</title>

    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>

</head>
<body>
<div id="blank" class="header" >
    <div v-back.tapmode class="back"></div>
    <span class="title">店铺简介</span>
</div>
<div id="app" class="top-container">
    <div class="feedback-textarea">
        <textarea v-focus v-model="introduction" placeholder="请输入店铺描述(50字以内)"></textarea>
    </div>
    <a class="btn-commit" v-myclick="commit">提交</a>
</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>

<script>

    var introduction,
        vm;
    apiready = function () {
        setBSImg();
        new Vue({
            el:'#blank'
        });
        var data = {member_id: getPrefs('member_id')};
        var callback = function (ret) {
            shopinfo = ret.content;
            introduction = shopinfo.introduction;
            initApp();
            api.parseTapmode();
        };
        pinet.post(URL.getShopInfo, data, callback);
        api.parseTapmode();
        addListeners();
    };

    function initApp() {
        vm = new Vue({
            el:'#app',
            data:{
                introduction:introduction,
            },
            watch:{
                introduction:function (n, o) {
                    this.nameByte = n.replace(/[^\x00-\xff]/g,"xx").length;
                    if(this.nameByte > 100){
                        this.introduction = o;
                    }
                }
            },
            methods:{
                commit:function () {
                    showProgress();
                    var data = {
                        member_id:getPrefs('member_id'),
                        introduction:this.introduction
                    };
                    var callback = function (ret) {
                        api.sendEvent({
                            name: 'updUser',
                            extra: {
                                introduction: vm.introduction
                            }
                        });
                        closeWin();
                    };
                    pinet.post(URL.updShopInfo, data, callback);
                }
            }
        })
    }

    function addListeners() {
        api.addEventListener({
            name: 'viewappear'
        }, function () {
            onPageStart();
        });

        api.addEventListener({
            name: 'viewdisappear'
        }, function (ret, err) {
            onPageEnd();
        });

        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            onPageEnd();
            api.closeWin();
        });
    }
</script>
</html>
